﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Principal;
using EnCor.Security;
using System.Threading;

namespace EnCor.Aspnet
{
    public class AspnetRuntime : Runtime, IHttpModule
    {
        private HttpApplication _Application;
        #region IHttpModule Members

        public void Dispose()
        {
            _Application.BeginRequest -= Application_BeginRequest;
            _Application = null;
        }

        public void Init(HttpApplication context)
        {
            _Application = context;
            _Application.AuthenticateRequest += new EventHandler(Application_AuthenticateRequest);
            context.BeginRequest += new EventHandler(Application_BeginRequest);
            _Application.PostAuthenticateRequest += new EventHandler(_Application_PostAuthenticateRequest);
            Start();
        }

        void _Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            
        }

        void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            InitializeSecurityContext();
            HttpContext.Current.User = SecurityContext.Current.Principal;
        }

        #endregion

        private void Application_BeginRequest(object sender, EventArgs e)
        {

        }
    }
}
